﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DPS.Prototype.Model;
using DPS.Prototype.Provider.Interface;
using DPS.DataModel;
using DPS.Prototype.Model.Adapter;
using System.Configuration;

namespace DPS.Prototype.Provider
{
    public class WorkOrderProvider : IWorkOrderProvider
    {
        private static string dataConnString = ConfigurationManager.ConnectionStrings["DPSConnectionString"].ConnectionString;
        public WorkOrderProvider()
        {
        }

        public List<WorkOrder> GetAllOpenWorkOrder()
        {
            List<WorkOrder> orders = new List<WorkOrder>();
            DPSDataModelDataContext dataContext = DataContextProvider.DataContext;
            var query = dataContext.DPSBatchTs.Where(batch => batch.BatchType == "WO" && batch.Status == "1").Select(b => b.BatchID);
            if (query.Count() > 0)
            {
                string batchId = query.First();
                List<DPSWorkOrderByBatchT> list = dataContext.DPSWorkOrderByBatchTs.Where(wo => wo.BatchID == batchId).ToList();
                list.ForEach(wo =>
                    {
                        orders.Add(WorkOrderAdapter.Adapter(wo));
                    }
                );
            }
            return orders;
        }
    }
}
